tensorflow.function
s only supports singleton tensorflow.Variable
s. This means the variable will be created on the first
call of the tensorflow.function
and will be reused across the subsequent calls. Creating a tensorflow.Variable
that is not a
singleton will raise a ValueError
.
import tensorflow as tf
@tf.function
def f(x):
v = tf.Variable(1.0)
return v
In the example above each time the function f
will be called a new tensorflow.Variable
will be created.